﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="HouseHoldingRunRepository.cs" company="DST Nexdox">
//   Copyright (c) DST Nexdox. All rights reserved.
// </copyright>
// <summary>
//   Defines the HouseHoldingRunRepository type.
// </summary>
// --------------------------------------------------------------------------------------------------------------------

namespace UnityRepository.Repositories
{
  using System;
  using System.Collections.Generic;
  using System.Linq;
  using EFRepository;
  using Entities;
  using UnityRepository.Contexts;
  using UnityRepository.Interfaces;

  public class HouseHoldingRunRepository : BaseEfRepository<HouseHoldingRun>, IHouseHoldingRunRepository
  {
    public HouseHoldingRunRepository(String connectionString)
      : base(new UnityDbContext(connectionString))
    {
    }

    public IList<HouseHoldingRun> GetTopFifteenRecentHouseHeldGrids(List<Int32> manCoIds)
    {
      return Entities
        .Where(hhr => manCoIds.Contains(hhr.GridRuns.FirstOrDefault().Documents.FirstOrDefault().ManCoId))
        .OrderByDescending(o => o.Id)
        .Take(15)
        .ToList();
    }
  }
}
